<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java包装类：面向对象编程的基石</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            position: relative;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            font-size: 0.75rem;
            color: #858585;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        .section-number {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 2.5rem;
            height: 2.5rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 700;
            margin-right: 1rem;
            flex-shrink: 0;
        }
        
        .feature-icon {
            width: 3rem;
            height: 3rem;
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        
        .highlight-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                Java包装类
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                面向对象编程的基石
            </p>
            <div class="flex justify-center space-x-4 text-sm">
                <span class="flex items-center"><i class="fas fa-clock mr-2"></i>阅读时间：8分钟</span>
                <span class="flex items-center"><i class="fas fa-layer-group mr-2"></i>深度解析</span>
                <span class="flex items-center"><i class="fas fa-code mr-2"></i>代码示例</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">包</span>装类在 Java 中是不可或缺的，它们通过将基本类型封装为对象，提供了面向对象的编程体验，增强了与集合框架、泛型、反射等特性的兼容性，并为开发者提供了额外的功能和性能优化手段。因此，包装类在 Java 开发中扮演了非常重要的角色。
            </p>
        </div>

        <!-- Concept Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-2xl font-bold mb-6 text-center">包装类体系结构</h2>
            <div class="mermaid">
                graph TD
                    A[基本数据类型] --> B[包装类]
                    B --> C[Integer]
                    B --> D[Double]
                    B --> E[Boolean]
                    B --> F[Character]
                    B --> G[Long]
                    B --> H[Float]
                    B --> I[Byte]
                    B --> J[Short]
                    
                    C --> K[自动装箱/拆箱]
                    C --> L[缓存机制]
                    C --> M[工具方法]
                    
                    style A fill:#f9f,stroke:#333,stroke-width:2px
                    style B fill:#bbf,stroke:#333,stroke-width:2px
                    style K fill:#bfb,stroke:#333,stroke-width:2px
                    style L fill:#fbf,stroke:#333,stroke-width:2px
                    style M fill:#ffb,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Feature Sections -->
        <div class="grid gap-8">
            <!-- Section 1 -->
            <section class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start">
                    <span class="section-number">1</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">面向对象的需求</h3>
                        <p class="text-gray-700 leading-relaxed mb-6">
                            Java 是一种面向对象的编程语言，几乎所有东西都是对象。基本数据类型（如 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">int</code>、<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">char</code>、<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">boolean</code> 等）并不是对象，它们不能调用方法，也不能直接参与泛型、集合框架等操作。包装类将基本数据类型封装为对象，使其具备对象的特性。
                        </p>
                        
                        <div class="grid md:grid-cols-3 gap-4 mb-6">
                            <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-4 rounded-lg text-center">
                                <i class="fas fa-box text-3xl text-purple-600 mb-2"></i>
                                <p class="font-semibold">int → Integer</p>
                            </div>
                            <div class="bg-gradient-to-br from-blue-50 to-indigo-50 p-4 rounded-lg text-center">
                                <i class="fas fa-font text-3xl text-blue-600 mb-2"></i>
                                <p class="font-semibold">char → Character</p>
                            </div>
                            <div class="bg-gradient-to-br from-green-50 to-teal-50 p-4 rounded-lg text-center">
                                <i class="fas fa-toggle-on text-3xl text-green-600 mb-2"></i>
                                <p class="font-semibold">boolean → Boolean</p>
                            </div>
                        </div>
                        
                        <div class="code-block">
                            <pre>int num = 5;
Integer wrappedNum = Integer.valueOf(num); // 将基本类型封装为对象</pre>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Section 2 -->
            <section class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start">
                    <span class="section-number">2</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">与 Java 集合框架的兼容性</h3>
                        <p class="text-gray-700 leading-relaxed mb-6">
                            Java 集合框架（如 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">ArrayList</code>、<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">HashMap</code> 等）只能存储对象，不能直接存储基本数据类型。如果想将基本数据类型的值存储在集合中，就必须使用相应的包装类。
                        </p>
                        
                        <div class="code-block mb-6">
                            <pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
list.add(10); // 这里的 10 自动装箱为 Integer 对象</pre>
                        </div>
                        
                        <p class="text-gray-700 leading-relaxed">
                            在这个例子中，<code class="bg-gray-100 px-2 py-1 rounded text-purple-600">10</code> 是基本类型 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">int</code> 的值，但由于 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">ArrayList</code> 只能存储对象，它被自动装箱为 <code class="bg-gray-100 px-2 py-1 rounded text-purple-600">Integer</code> 对象。
                        </p>
                    </div>
                </div>
            </section>

            <!-- Section 3 -->
            <section class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start">
                    <span class="section-number">3</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">提供更多功能</h3>
                        <p class="text-gray-700 leading-relaxed mb-6">
                            包装类不仅仅是基本类型的简单封装，它们还提供了许多有用的方法和常量：
                        </p>
                        
                        <div class="grid md:grid-cols-2 gap-6 mb-6">
                            <div class="bg-gradient-to-r from-purple-50 to-pink-50 p-6 rounded-lg">
                                <div class="feature-icon">
                                    <i class="fas fa-exchange-alt"></i>
                                </div>
                                <h4 class="font-bold mb-2">类型转换</h4>
                                <p class="text-gray-600"><code class="bg-white px-2 py-1 rounded">Integer.parseInt()</code> 将字符串转换为 int</p>
                            </div>
                            <div class="bg-gradient-to-r from-blue-50 to-indigo-50 p-6 rounded-lg">
                                <div class="feature-icon">
                                    <i class="fas fa-check-circle"></i>
                                </div>
                                <h4 class="font-bold mb-2">数值验证</h4>
                                <p class="text-gray-600"><code class="bg-white px-2 py-1 rounded">Double.isNaN()</code> 判断是否为非数字</p>
                            </div>
                        </div>
                        
                        <div class="code-block">
                            <pre>String str = "123";
int num = Integer.parseInt(str); // 将字符串转换为 int</pre>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Section 4 -->
            <section class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="flex items-start">
                    <span class="section-number">4</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4">实现自动装箱和拆箱</h3>
                        <p class="text-gray-700 leading-relaxed mb-6">
                            自动装箱（Autoboxing）和拆箱（Unboxing）是 Java 1.5 引入的特性，使得基本类型与包装类之间的转换更加简洁和方便。
                        </p>
                        
                        <div class="bg-gradient-to-r from-in